Repository navigation
Big endian C codegen - #79
Merged
hit9 merged 4 commits intoJun 19, 2026
Merged
Conversation
…nter indexing The encoder's ((unsigned char *)&(field))[fi] pattern accesses bytes via host memory layout, which gives wrong values on big-endian targets (e.g. TMS570) because fi=0 maps to the MSB instead of the LSB. Replace both encoder and decoder items with explicit bit-shift arithmetic that is endian-neutral: Encoder: ((unsigned_type)(chain) >> (fi*8 + shift)) & mask Decoder: chain |= (chain_type)(((unsigned)s[si] shift) & mask) << (fi*8)) The decoder always uses |= rather than = so it accumulates bytes without clobbering already-written ones; a memset(m, 0, sizeof(*m)) at the top of each generated Decode function provides the required zero baseline. string.h is included in the generated .c file for optimization mode. Regenerate C/CPP optimization-mode examples to reflect the new output. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
|
Thanks. I make a continuation on top of this PR on #81 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When compiling for a big-endian platform (TMS570 -- big endian ARM), we observed byte-swapping behaviour in encoder and decoder. The round-trip result encoding on a big endian platform and decoding on little endian, was byte-swapped. This fix changes the code emitted to use endian independent bit-shifts, rather than pointer math, to encode and decode.
It passes the CI tests, and we have tested that it resolves the problem on real hardware. We would love for this to be accepted upstream.